package com.singzi.leetcode.jianzhiOffer;

import com.singzi.leetcode.obj.TreeNode;

import java.util.*;

public class T0032 {
}
class Solution0032 {
    public int[] levelOrder(TreeNode root) {
        if(root == null) return new int[]{};
        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        while (!queue.isEmpty()){
            TreeNode tree = queue.remove();
            arrayList.add(tree.val);
            if(tree.left != null) queue.add(tree.left);
            if(tree.right != null) queue.add(tree.right);
        }
        int []result = new int[arrayList.size()];
        int  i = 0;
        for(Integer num:arrayList){
            result[i] = num;
            i++;
        }
        return result;
    }
}